<template>
  <el-card class="app-container">
    <c-u-r-d-table :option="option"/>
  </el-card>
</template>

<script>
import ColumnType from '@/framework/constant/ColumnType'
import CURDTable from '@/framework/components/table/CURDTable'
import { managerApi } from '@/feature/system/infra/api/managerApi'
import { roleApi } from '@/feature/system/infra/api/roleApi'
import ValidStatusEnum from '@/framework/constant/ValidStatusEnum'

/**
 * {
          label: '密码',
          prop: 'password',
          type: ColumnType.PASSWORD,
          showFilter: ({ isEdit }) => !isEdit,
          hiddenInTable: true,
          rules: [{
            required: true,
            message: '密码不能为空'
          }]
        },
 */
export default {
  components: { CURDTable },
  methods: {
    async handleReset({ arg: { id } }) {
      await this.$confirm('确认重置密码吗？', '提示')
      const newPwd = await managerApi.resetManagerPwd(id)
      await this.$alert('重置密码成功，请使用新密码：' + newPwd, '提示')
    },
    async onAddSuccess(data) {
      await this.$alert('创建账号成功，密码：' + data, '提示')
    }
  },
  data() {
    return {
      option: {
        requestApi: managerApi,
        exportOption: {
          remote: true
        },
        columns: [{
          label: '登录账号',
          prop: 'username',
          type: ColumnType.TEXT,
          searchable: true,
          readonly({ isEdit }) {
            return isEdit
          },
          rules: [{
            required: true,
            message: '用户名不能为空'
          }]
        }, {
          label: '状态',
          prop: 'status',
          type: ColumnType.SELECT,
          options: ValidStatusEnum,
          width: 100,
          hiddenInForm: true,
          searchable: true
        }, {
          label: '角色',
          tagMode: false,
          width: 160,
          prop: 'roleId',
          type: ColumnType.SELECT,
          options: roleApi.roleListAll(),
          searchable: true,
          rules: [{
            required: true,
            message: '请选择角色'
          }]
        }, {
          label: '姓名',
          prop: 'realname',
          span: 12,
          width: 100
        }, {
          label: '备注',
          prop: 'note',
          span: 24,
          type: ColumnType.TEXTAREA,
          rows: 3
        }, {
          label: '上次登录时间',
          prop: 'lastLoginTime',
          type: ColumnType.DATETIME,
          hiddenInForm: true
        }, {
          label: '上次登录ip',
          prop: 'lastLoginIp',
          hiddenInForm: true
        }, {
          label: '创建时间',
          prop: 'gmtCreate',
          type: ColumnType.DATETIME,
          hiddenInForm: true
        }, {
          label: '修改时间',
          prop: 'gmtModified',
          type: ColumnType.DATETIME,
          hiddenInForm: true
        }]
      }
    }
  }
}
</script>

